home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 199_01 / ged.c < prev    next >
Text File  |  1987-12-15  |  19KB  |  754 lines

  1. /*
  2. Header:           CUG199;
  3. Title:            Module 0 of ged editor;
  4. Last Updated:     12/06/87;
  5.  
  6. Description:     "PURPOSE: initialise; process commands";
  7.  
  8. Keywords:         e, editor, qed, ged, DeSmet, MSDOS;
  9. Filename:         ged.c;
  10. Warnings:        "O file must be present during link of ged";
  11.  
  12. Authors:          G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
  13. Compilers:        DeSmet 3.0;
  14.  
  15. References:
  16. Endref;
  17. */
  18.  
  19. /*
  20. e/qed/ged screen editor
  21.  
  22. (C) G. Nigel Gilbert, MICROLOGY, 1981 -  August-December 1981
  23.  
  24. Modified:   Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  25.             March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  26.  
  27.             May       1986:  qed converted to ged         (Mel Tearle)
  28.             August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  29.  
  30. File:       ged.c
  31.  
  32. Functions:  main, initialise, edit, finish, dispose, xit,
  33.             askforfile, seldisk
  34. */
  35.  
  36. #include "ged.h"
  37.  
  38. #ifdef MSC
  39. jmp_buf  mark;
  40. #endif
  41.  
  42. void main(argc,argv)
  43. char **argv;
  44. int argc;
  45. {
  46. int argn;
  47. int i;
  48. char *dig;
  49.  
  50. /* --------------------- Default option settings ---------------------*/
  51.  
  52. initjmp =    1;     /* jmp to line 1 */
  53. autoin  =  YES;     /* auto indent  [YES/NO] */
  54. backup  =  YES;     /* make ".BAK" file [YES/NO] */
  55.  
  56.  
  57. /***********************************************************************/
  58. /*** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE ***/
  59. /***********************************************************************/
  60.  
  61.    readall =  YES;     /* read as much text as possible up to memory */
  62.  
  63. /***********************************************************************/
  64. /*** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE ***/
  65. /***********************************************************************/
  66.  
  67.  
  68. trail   =   NO;     /* don't strip trailing blanks [YES/NO] */
  69.  
  70. tabwidth    =   4;  /* tab stops every n cols [number] */
  71. blockscroll = YES;  /* don't horizontal scroll whole page, just current line */
  72. pagingdisk  =   0;  /* create buffer file on this disk -
  73.                        set to either 0 (for currently logged-in disk)
  74.                        or to desired disk letter  (eg 'B') */
  75.  
  76. rtmarg    =  REFORM;   /* default for reformat only - no wordwrap */
  77. defext[0] =    '\0';   /* default extension */
  78.  
  79. window = WINDOW;
  80.  
  81. /* ------------------ End of default option settings -------------------- */
  82.  
  83.  
  84. if ( ( _os( VERNO, 0 ) & 0x00ff ) < 2 )  {
  85.        putstr( "Ged Error: Must use MSDOS vers 2.x with 'ged'" );
  86.        exit(0);
  87. }
  88.  
  89.  
  90. inbufp = 0;
  91. filename[0] = name[0] = '\0';
  92.  
  93. argn = 0;
  94. while ( ++argn < argc )
  95.   if ( *argv[argn] == '-' )  {
  96.         dig = argv[argn]+1;
  97.         switch( toupper(*dig) )  {
  98.            case 'A' :
  99.                 autoin = ( char ) !autoin;
  100.                 break;
  101.            case 'B' :
  102.                 backup = ( char ) !backup;
  103.                 break;
  104.            case 'Q' :
  105.                 readall = ( char ) !readall;
  106.                 break;
  107.            case 'H' :
  108.                 blockscroll = ( char ) !blockscroll;
  109.                 break;
  110.            case 'T' :
  111.                 tabwidth = 0;
  112.                 while (*++dig) tabwidth = tabwidth*10+*dig-'0';
  113.                 break;
  114.            case 'S' :
  115.                 trail = ( char ) !trail;
  116.                 break;
  117.            case 'D' :
  118.                 pagingdisk = toupper(*(dig+1));
  119.                 if ( pagingdisk >= 'A' && pagingdisk <= 'P' )
  120.                      break;
  121.            default  :
  122.                 if ( isdigit( *dig ) )  {
  123.                      initjmp = atoi( (argv[argn]+1 ) );
  124.                      break;
  125.                 }
  126.                 putstr( "Ged Error: Illegal option: " );
  127.                 putstr( argv[argn] );
  128.                 exit(1);
  129.                 }
  130.   }
  131.   else strcpy( filename[0] ? name : filename, argv[argn] );
  132.  
  133. ans[0] = patt[0] = changeto[0] = opts[0] = '\0';
  134.  
  135.  
  136. /* ----------------------  start here  -------------------- */
  137.  
  138. keytranslate();
  139.  
  140. do  {
  141.   initialise();
  142.   edit();
  143. }
  144. while (YES);
  145. }
  146.  
  147. /* -----------------------  end main   ------------------- */
  148.  
  149.  
  150. void initialise()
  151. {
  152. int i;
  153.  
  154. cursorx  = charn   = offset = lastoff = from = 0;
  155. histptr  = histcnt = ncommand = to = 0;
  156.  
  157. cursory  = cline = topline  = lastread = lastl = findir = jmpto = 1;
  158.  
  159. changed  = blocking = isdim = repeat = NO;
  160. replace  = blankedmess = NO;
  161. screen   = NO;
  162.  
  163. if ( overtype )  ;  else  NO;
  164.  
  165. altered   = goteof = YES;
  166. errmess   = '\0';
  167. lastgraph = NULL;
  168.  
  169. pfirst   = -100;    text[0]  = '\0';
  170.  
  171.  
  172. curdsk = _os( CURDSK, 0 );
  173.  
  174.  
  175. initvm();
  176. scr_setup();
  177. scr_cursoff();
  178.  
  179. if ( filename[0] )  {
  180.      scr_clr();
  181.  
  182. scr_putstr( 11, 10,
  183.    "╔═════════════════════════════════════════════════════════╗", RSFW );
  184. scr_putstr( 11, 11,
  185.    "║   qed editor version 4.6b  MICROLOGY 1983 - JWH 1985    ║", RSFW );
  186. scr_putstr( 11, 12,
  187.    "║        m/ged version 2.00  Mel Tearle 1987              ║", RSFW );
  188. scr_putstr( 11, 13,
  189.    "║                    » ged - 12/06/87 «                   ║", RSFW );
  190. scr_putstr( 11, 14,
  191.    "╚═════════════════════════════════════════════════════════╝", RSFW );
  192. scr_delete( 0,24 );
  193.  
  194.  
  195.      /* open a file, if it fails then try again to
  196.       * open it using filename plus default extension
  197.       */
  198.      while ( opentext( filename ) == FAIL )  {
  199.              askforfile();
  200.              if ( !filename[0] )  goto  newfile;
  201.      }
  202.      lastl = UNKNOWN;  lastread = 0;  goteof = NO;
  203.  
  204.      if ( name[0] )  {
  205.           strcpy( filename, name );
  206.           name[0] = '\0';
  207.      }
  208. }       /* end - if filename */
  209.  
  210. newfile:
  211.   errmess = NULL;
  212.  
  213.   format( filename );
  214.  
  215.  
  216.  /* read as much text to fill memory or end of file
  217.   */
  218.  if ( readall )
  219.       for ( i = 1; (! ( usage[slotsinmem-1] ) && ( !( goteof ) ) ); i += 100 )
  220.             readtext(i);
  221.  
  222.  gettext(1);
  223.  scr_clr();
  224.  
  225.  if ( initjmp > 2)  {              /* (2-1) is a bad jump from line 1 */
  226.       jumpline( initjmp-cline );   /* not possible to do init jump to 2*/
  227.       initjmp = 0;
  228.  }
  229.  else
  230.      putpage();
  231.  
  232. setstatusname();
  233. putstatusline( cline );
  234.  
  235. show_fkeys();
  236. }                  /* end - initialise  */
  237.  
  238.  
  239. /* command processor
  240.  */
  241. void edit()
  242. {
  243. unsigned char c;
  244.  
  245. int  inc, i, to, oldcrx;
  246.  
  247. #ifdef  MSC
  248.   setjmp( mark );
  249. #else
  250.   setjmp(0);
  251. #endif
  252.  
  253. while ( YES )  {
  254.   goodline = cline;     /* restore environment */
  255.   storehist = YES;      /* makesure we're saving history */
  256.   unmess();             /* check if topline has changed */
  257.  
  258.   if ( blankedmess )  {
  259.        putstatusline( cline );
  260.        blankedmess = NO;
  261.   }
  262.   else
  263.        putlineno( cline );
  264.  
  265.   resetcursor();
  266.   scr_curson();
  267.   c = getkey();
  268.  
  269.   if ( ( ncommand++ % 32 ) == 0 )   show_time();
  270.  
  271.   if ( errmess != NULL )  errmess =  NULL;
  272.     switch(c)  {
  273.       case UPPAGE :
  274.            movepage(-1);
  275.            break;
  276.       case DOWNPAGE :
  277.            movepage(0);
  278.            break;
  279.       case DOWNKEY :
  280.            moveline(1);
  281.            break;
  282.       case UPKEY :
  283.            moveline(-1);
  284.            break;
  285.       case SCRLDNKEY :
  286.            oldcrx = cursorx;
  287.            to = plast - cline;
  288.            moveline(to);
  289.            inc = ( ( moveline(1) == YES ) ? 1 : 0 );
  290.            cursorx = oldcrx;
  291.            moveline( ( ( cline - to ) <= pfirst )
  292.                      ? ( topline - cursory ) : ( -to - inc ) );
  293.            break;
  294.       case SCRLUPKEY :
  295.            oldcrx = cursorx;   /* save current cursorx */
  296.            to = topline - cursory;
  297.            moveline(to);
  298.            inc = ( ( moveline(-1) == YES ) ? 1 : 0 );
  299.            cursorx = oldcrx;
  300.            moveline( ( ( cline - to ) >= plast )
  301.                      ? ( SHEIGHT - cursory ) : ( -to + inc ) );
  302.            break;
  303.       case DELLNKEY :
  304.            changed = YES;
  305.            text[0] = '\0';
  306.            crdelete( ( cline == lastl ? -1 : 0 ) );
  307.            break;
  308.       case BLOCKKEY :
  309.         switch ( to = blockops() )  {
  310.           case YES :  return;
  311.                  /*   break;  */
  312.           case 'x' :
  313.           case 'q' :  if